package bw;

import bw.pojo.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EmailController {

    @Autowired
    private JavaMailSender javaMailSender;
    //邮件发送者
    @Value("${spring.mail.username}")
    private String from;

    @PostMapping("/shop")
    public boolean shop(@RequestBody Course course, @RequestParam("user") String[] user){

        SimpleMailMessage message = new SimpleMailMessage();
        //邮件发送者
        message.setFrom(from);
        //群发邮件
        message.setTo(user);
        //邮件主题
        message.setSubject("下单成功提醒");
        //邮件内容
        message.setText("注意刚刚购买的商品已经下单成功,请尽快完成支付");
        //发邮件
        javaMailSender.send(message);
        return true;
    }
}
